<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">

      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="应聘人姓名">
          <a-input placeholder="请输入应聘人姓名" v-decorator="['employName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="性别">
          <a-input placeholder="请输入性别" v-decorator="['sex', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="电话号码">
          <a-input placeholder="请输入电话号码" v-decorator="['phoneNumber', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="身份证号码">
          <a-input placeholder="请输入身份证号码" v-decorator="['idNumber', {}]"/>
        </a-form-item>
        <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="出生日期">
            <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'birthTime', {}]"/>
        </a-form-item>
        <a-form-item
         :labelCol="labelCol"
         :wrapperCol="wrapperCol"
         label="岗位">
         <a-input placeholder="请输入岗位" v-decorator="['position', {}]"/>
       </a-form-item>
       <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="待遇需求">
        <a-input placeholder="请输入待遇需求" v-decorator="['salary', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="婚姻状况">
          <a-input placeholder="请输入婚姻状况" v-decorator="['maritalStatus', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="引荐人">
          <a-input placeholder="请输入引荐人" v-decorator="['referrer', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学校名称">
          <a-input placeholder="请输入学校名称" v-decorator="['schoolName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专业">
          <a-input placeholder="请输入专业" v-decorator="['profession', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学位">
          <a-input placeholder="请输入学位" v-decorator="['graduate', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学历">
          <a-input placeholder="请输入学历" v-decorator="['education', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="特长">
          <a-input placeholder="请输入特长" v-decorator="['speciality', {}]"/>
        </a-form-item>
       <a-form-item
         :labelCol="labelCol"
         :wrapperCol="wrapperCol"
         label="身高">
         <a-input placeholder="请输入身高" v-decorator="['stature', {}]"/>
       </a-form-item>
       <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="前任公司名称">
          <a-input placeholder="请输入前任公司名称" v-decorator="['lastCompany', {}]"/>
        </a-form-item>
        <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="上份工作入职日期">
            <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'startTime', {}]"/>
        </a-form-item>
       <a-form-item
       :labelCol="labelCol"
       :wrapperCol="wrapperCol"
       label="上份工作离职日期">
           <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'endTime', {}]"/>
       </a-form-item>
        <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="上份工作岗位">
           <a-input placeholder="请输入上份工作岗位" v-decorator="['lastPosition', {}]"/>
         </a-form-item>
         <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="上份工作薪资">
            <a-input placeholder="请输入工作薪资" v-decorator="['lastSalary', {}]"/>
          </a-form-item>
          <a-form-item
             :labelCol="labelCol"
             :wrapperCol="wrapperCol"
             label="离职原因">
             <a-input placeholder="请输入离职原因" v-decorator="['dimissionCause', {}]"/>
           </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入主键" type="hidden" v-decorator="['pkEmploy', validatorRules.pkEmploy ]"/>
        </a-form-item>
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">1确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  export default {
    name: "recruitmentManageModal",
    mixins:[JeecgListMixin],
    data() {
      return {
        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          //pkManagement:{rules: [{ required: true, message: '请输入主键!' }]},
        },
        url: {
          list: "/recruitment/recruitmentManage/list",
          add: "/recruitment/recruitmentManage/add",
          edit: "/recruitment/recruitmentManage/edit"
        },
      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'pkEmploy', 'employName', 'sex', 'phoneNumber', 'position', 'schoolName', 'education', 'profession', 'lastCompany', 'lastPosition', 'idNumber', 'referrer','salary','maritalStatus','referrer','schoolName','graduate','education','speciality','stature','lastCompany','startTime','lastSalary','dimissionCause',))
          //时间格式化
          this.form.setFieldsValue({birthTime: this.model.birthTime ? moment(this.model.birthTime) : null})
          this.form.setFieldsValue({startTime: this.model.startTime ? moment(this.model.startTime) : null})
          this.form.setFieldsValue({endTime: this.model.endTime ? moment(this.model.endTime) : null})
        });

      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            console.log(this.model.pkEmploy);
            if (!this.model.pkEmploy) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.birthTime = formData.birthTime ? formData.birthTime.format('YYYY-MM-DD HH:mm:ss') : null;
            formData.startTime = formData.startTime ? formData.startTime.format('YYYY-MM-DD HH:mm:ss') : null;
            formData.endTime = formData.endTime ? formData.endTime.format('YYYY-MM-DD HH:mm:ss') : null;

            console.log(this)
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })


          }
        })
      },
      handleCancel() {
        this.close()
      }
    },
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>